import { request } from "@/utils/service"
import { AxiosPromise } from "axios"
import { MenuQuery, MenuVO, MenuForm, MenuTreeOption, RoleMenuTree } from "./types"

//#region 主表接口
// 菜单-获取路由
export function getRouters() {
  return request<any>({
    url: "/ocean-base/sysMenu/getRouters",
    method: "get"
  })
}

//#endregion

/**
 * 查询菜单列表
 *
 * @param {any} query 参数
 * @returns
 */
export const listMenu = async (query?: any) => {
  return await request({
    url: "/ocean-base/sysMenu/findList",
    method: "post",
    data: query
  })
}

/**
 * 查询菜单分页列表
 *
 * @param {any} query 参数
 * @returns
 */
export const pageList = async (query?: any) => {
  return await request({
    url: "/system/menu/page",
    method: "get",
    params: query
  })
}

/**
 * 查询菜单详细
 *
 * @param {string} menuId 菜单ID
 * @returns
 */
// 查询菜单详细
export const getMenu = (menuId: string | number): AxiosPromise<MenuVO> => {
  return request({
    url: "/system/menu/" + menuId,
    method: "get"
  })
}

/**
 * 查询菜单下拉树结构
 *
 * @returns
 */
export const treeselect = async () => {
  return await request({
    url: "/system/menu/treeselect",
    method: "get"
  })
}

/**
 * 根据角色ID查询菜单下拉树结构
 *
 * @param {string} roleId 角色ID
 * @returns
 */
export const roleMenuTreeSelect = async (roleId: string) => {
  return await request({
    url: "/system/menu/roleMenuTreeSelect/" + roleId,
    method: "get"
  })
}

/**
 * 新增菜单
 *
 * @param {object} param 菜单Obj
 * @returns
 */
export const addMenu = async (param: any) => {
  return await request({
    url: "/system/menu",
    method: "post",
    data: param
  })
}

/**
 * 修改菜单
 *
 * @param {object} param 菜单Obj
 * @returns
 */
export const updateMenu = async (param: any) => {
  return await request({
    url: "/system/menu",
    method: "put",
    data: param
  })
}

/**
 * 删除菜单
 *
 * @param {string} menuId 菜单ID
 * @returns
 */
export const delMenu = async (menuId: string) => {
  return await request({
    url: "/system/menu/" + menuId,
    method: "delete"
  })
}

/**
 * 批量删除
 *
 * @param {string} ids 菜单ID数组
 * @returns
 */
export const batchDelMenu = async (ids: string) => {
  return await request({
    url: "/system/menu/batchDel/" + ids,
    method: "delete"
  })
}
